package com.credit.jumu.calculator.utils;

import java.math.BigDecimal;

/**
 * Created by Administrator on 2017/11/28/028.
 */

public class CalculatorUtil {
	//月供
	public static double monthly(double benjin,double monthlilv,int months){
	//	double everyone = (benjin*monthlilv*(1+monthlilv));
		double everytwo = StringHandleUtil.toOnlytwoDouble(Math.pow(benjin*monthlilv*(1+monthlilv),months));
		double everythere = Math.pow((1+monthlilv),months)-1;
		double everythere1 = Math.pow(3,3);
		return everytwo/everythere;
	}



//每月还
	public static double getPerMonthPrincipalInterest(double invest, double yearRate, int totalmonth) {
		double monthRate = yearRate / 12;
		BigDecimal monthIncome = new BigDecimal(invest)
				.multiply(new BigDecimal(monthRate * Math.pow(1 + monthRate, totalmonth)))
				.divide(new BigDecimal(Math.pow(1 + monthRate, totalmonth) - 1), 2, BigDecimal.ROUND_DOWN);
		return monthIncome.doubleValue();
	}
}
